package com.itheima.controller;

import com.itheima.bean.exception.BusinessException;
import com.itheima.bean.exception.SystemException;
import com.itheima.bean.vo.Code;
import com.itheima.bean.vo.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice  //异常处理通知
public class ProjectExceptionAdvice {
    @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(BusinessException ex){

        return  new Result(ex.getCode(),ex.getMessage());
    }
    @ExceptionHandler(SystemException.class)
    public Result doSystemException(SystemException ex){

        return  new Result(ex.getCode(),ex.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public Result doException(Exception ex){

        return  new Result(Code.EXCEPTION_ERR,ex.getMessage());
    }
}
